package com.qinglei.recoup.longconn.config;

import com.qinglei.recoup.common.exception.RecoupException;
import com.qinglei.recoup.longconn.properties.OssProperties;
import com.qinglei.recoup.longconn.service.OssService;
import com.qinglei.recoup.longconn.service.impl.OssServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

import javax.annotation.Resource;

@Configuration
@Slf4j
@ConditionalOnProperty(prefix = "recoup.longconn.oss", name = "enable", havingValue = "true")
public class OssConfig {

    @Resource
    private OssProperties ossProperties;

    @Bean
    @Order(5)
    public OssService getOssStorage() throws RecoupException {
        log.info("create oss storage instance");
        return new OssServiceImpl(ossProperties);
    }

}

